package com.jnu.keepaccounts.history;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.jnu.keepaccounts.R;
import com.jnu.keepaccounts.record.Tab;

import java.util.ArrayList;

public class History extends AppCompatActivity {
    TabLayout tabLayout;
    ViewPager viewPager;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.history);

        ActionBar actionBar = getSupportActionBar();
        if(actionBar!=null){
            actionBar.hide();
        }
        ImageButton imageButton1 = findViewById(R.id.image_back);
        imageButton1.setOnClickListener(v -> {
            finish();
        });

        ImageButton imageButton = findViewById(R.id.button_menu);
        imageButton.setOnClickListener(v -> {
            Toast.makeText(this,"还没做",Toast.LENGTH_SHORT).show();
        });
        tabLayout = findViewById(R.id.tab_layout_history);
        viewPager = findViewById(R.id.view_pager_history);

//tab名
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("按天");
        arrayList.add("按月");
        arrayList.add("按年");
        arrayList.add("自定义");

        prepareViewPager(viewPager,arrayList);

        tabLayout.setupWithViewPager(viewPager);

    }

    public void prepareViewPager(ViewPager viewPager,ArrayList<String> arrayList){
        Tab.MainAdapter adapter = new Tab.MainAdapter(getSupportFragmentManager());
        DayFragment dayFragment = new DayFragment();
        MonthFragment monthFragment = new MonthFragment();
        YearFragment yearFragment = new YearFragment();
        SelfFragment selfFragment = new SelfFragment();

        Bundle bundle = new Bundle();

        bundle.putString("title",arrayList.get(0));

        dayFragment.setArguments(bundle);

        adapter.addFragment(dayFragment,arrayList.get(0));

        Bundle bundle1 = new Bundle();

        bundle1.putString("title",arrayList.get(1));

        monthFragment.setArguments(bundle1);

        adapter.addFragment(monthFragment,arrayList.get(1));

        Bundle bundle2 = new Bundle();

        bundle2.putString("title",arrayList.get(2));

        yearFragment.setArguments(bundle2);

        adapter.addFragment(yearFragment,arrayList.get(2));

        Bundle bundle3 = new Bundle();

        bundle3.putString("title",arrayList.get(3));

        selfFragment.setArguments(bundle3);

        adapter.addFragment(selfFragment,arrayList.get(3));

        viewPager.setAdapter(adapter);
    }
}
